InterviewQuestions

Graphic Interview Question

C++

Day1

  1. What are references in C++?
  2. What is a virtual function in C++ and why is it used?
  3. What is the difference between new and malloc()?
  4. Explain the inline keyword.

Day2

  1. What is the difference between reference and pointer?
  2. What is the difference between function overloading and operator overloading?
  3. What is the difference between virtual functions and pure virtual functions?
  4. When should we use multiple inheritance?
  5. What are destructors in C++?
  6. Is destructor overloading possible? If yes then explain and if no then why?
  7. Which operations are permitted on pointers?
  8. What is the purpose of the delete operator?

Day3

  1. What is virtual inheritance?
  2. What is polymorphism in C++?
  3. How delete [] is different from delete?
  4. What do you know about friend class and friend function?
  5. What is a virtual destructor?
  6. What is an Overflow Error?
  7. What does the Scope Resolution operator do?
  8. What are the C++ access modifiers?
  9. Can you compile a program without the main function?
  10. What is STL?
  11. Define inline function. Can we have a recursive inline function in C++?
  12. What is an abstract class and when do you use it?

Day4

  1. Define inline function. Can we have a recursive inline function in C++?
  2. What are the static data members and static member functions?
  3. Define the Block scope variable.
  4. What is the function of the keyword “Auto”?
  5. Define namespace in C++.
  6. When is void() return type used?
  7. What is the difference between shallow copy and deep copy?
  8. Can we call a virtual function from a constructor?
  9. What are void pointers?

Graphics Questions

Day1

  1. What is dot product and cross product
  2. How does a rendering pipeline work?
  3. Do you use GPU profiling tools?

Day2

  1. What are VBO and VAO in OpenGL?
  2. What buffers are used in OpenGL and what are their purposes?
  3. What are the main types of shaders and their roles?
  4. How would you draw a triangle in OpenGL?
  5. What is deferred rendering? Pros and cons?
  6. How is anti-aliasing implemented?

Day4

  1. What Is Bitmap?
  2. What Are The Raster And Vector Graphics?
  3. Write The Difference Between Vector And Raster Graphics?
  4. What Is Scaling In Computer Graphics?

Day5

  1. How to perform model rotation, translation, and scaling using matrices?
  2. Explain the role of homogeneous coordinates
  3. What is normal mapping? How does it affect rendering?
  4. Explain the roles of uniform, attribute, and varying in GLSL
  5. How to implement the Blinn-Phong lighting model in shaders?

Game Ungine

Day1

  1. Differences between Unreal Engine 4 (UE4) and Unreal Engine 5 (UE5)

JAVA

Day1

  1. What is the difference between a thread and a process?
  2. What are the ways to create threads in Java?
  3. What are the different states in the lifecycle of a thread?
  4. What is the purpose of the synchronized keyword?
  5. What is the difference between synchronized methods and synchronized blocks?
  6. What is a deadlock? How can it be avoided?
  7. What are the purposes of wait(), notify(), and notifyAll()?
  8. Why are wait(), notify(), and notifyAll() defined in the Object class?
  9. Why must wait(), notify(), and notifyAll() be called within a synchronized block?

Day2

  1. Checked vs. unchecked exceptions?
  2. When do you use try-with-resources?
  3. String vs StringBuilder vs StringBuffer?
  4. What are lambda expressions?
  5. Explain the Stream API.
  6. ArrayList vs. LinkedList?
  7. How does a HashMap work?
  8. Explain SQL JOINs.
  9. What are ACID properties?
  10. When pick NoSQL over SQL?
  11. What’s IoC and DI?
  12. How does Spring Boot help?
  13. What are React components?
  14. How do you manage state?
  15. Two Sum solution?
  16. Daily Git workflow?
  17. Why unit testing?

Day3

  1. What does JVM comprise?
  2. What’s object-oriented programming? Is Java one?
  3. What’s aggregation in Java?
  4. What’s the superclass in Java?
  5. What’s the difference between finally and finalize?
  6. What’s an anonymous inner class?
  7. What’s a system class?
  8. How do you create a daemon thread?
  9. Does Java support global variables?
  10. How do you make an RMI object?
  11. Time slicing vs preemptive scheduling?
  12. What kind of thread is the garbage collector?

Experience

  1. If given a .mp4 file, how would you use FFmpeg to convert it into .ts or .m3u8 format?

  2. Have you checked FFmpeg’s console logs? How do you interpret the output?

  3. If a video plays with stuttering or high latency, what could be the causes? How can FFmpeg help diagnose it?

  4. Which protocols did you use for video streaming in your project, and why?

  5. Can you briefly describe how RTSP and HLS work?

  6. If a new streaming protocol comes out, how would you typically go about learning and experimenting with it?

  7. What were your main use cases for FFmpeg in your project? What functionalities did you implement using FFmpeg, such as transcoding, remuxing, screenshotting, or segmenting?

  8. Did you use FFmpeg via command-line or by integrating its API? Why did you choose that approach?

  9. Have you encountered audio-video synchronization issues? How did you handle desynchronization?

  10. Have you processed videos with different resolutions, frame rates, or bitrates? How did you adjust them with FFmpeg?

  11. Have you used FFmpeg for real-time streaming? How was it done?

  12. In your project, what were the use cases for RTSP, HLS, and WebRTC respectively, and why did you choose them?

  13. How does HLS work basically? What is the typical latency, and what are its pros and cons?

  14. What are the main differences between RTSP and HLS? Which transport protocol does RTSP use?

  15. How did you integrate these protocols? Did you use third-party media servers or build your own relay service?

Algorithm

Two Sum

Problem Description
Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
The order of the returned indices does not matter.

Function Signature Example

1
2
3
4
5
cpp


复制编辑
vector<int> twoSum(vector<int>& nums, int target);

Example
Input:

1
2
3
4
5
ini


复制编辑
nums = [2, 7, 11, 15], target = 9

Output:

1
2
3
4
5
6
csharp


复制编辑
[0, 1]
// Because nums[0] + nums[1] == 9

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Only one valid answer exists.

Solution Approach

Step 1: Clarify

  • Should we return indices or just a boolean indicating if such a pair exists?mrCan the numbers be negative?
  • Will the array always contain exactly one solution?

Step 2: Brute Force (O(n²))
Check every pair (i, j):

1
2
3
4
5
6
7
8
9
cpp


复制编辑
for (int i = 0; i < nums.size(); i++) {
for (int j = i + 1; j < nums.size(); j++) {
if (nums[i] + nums[j] == target) return {i, j};
}
}

Step 3: Optimized Solution (O(n) average)
Use a hash map to store numbers and their indices:

1
2
3
4
5
6
7
8
9
10
11
12
cpp


复制编辑
unordered_map<int, int> seen;
for (int i = 0; i < nums.size(); i++) {
int complement = target - nums[i];
if (seen.count(complement)) {
return {seen[complement], i};
}
seen[nums[i]] = i;
}

Step 4: Complexity

  • Time: O(n) average, O(n²) worst-case due to hash collisions.
  • Space: O(n) for the hash map.

Step 5: Edge Cases

  • Array contains duplicates (e.g., [3, 3] with target 6).
  • Negative numbers.
  • Minimum size array of length 2.

Alright — I’ll give you several other classic algorithm interview problems in the same English detailed format as the Two Sum example.
I’ll pick problems across different categories so you have a rounded set, and each will follow the same structure: Description → Example → Constraints → Solution Approach → Complexity → Edge Cases.

1. Reverse Linked List (LC 206)

Problem Description
Given the head of a singly linked list, reverse the list, and return the reversed list.

Function Signature Example

1
ListNode* reverseList(ListNode* head);

Example

1
2
Input:  head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]

Constraints

  • The number of nodes is in the range [0, 5000].
  • -5000 <= Node.val <= 5000

Solution Approach

  1. Iterative:
    • Use three pointers: prev, curr, next.
    • Iterate through the list, reversing the .next pointer at each step.
  2. Recursive:
    • Reverse the rest of the list, then set the next node’s .next to the current node.

Complexity

  • Time: O(n)
  • Space: O(1) for iterative, O(n) recursion stack for recursive.

Edge Cases

  • Empty list (nullptr).
  • Single node.

2. Middle of the Linked List (LC 876)

Problem Description
Given the head of a singly linked list, return the middle node.
If there are two middle nodes, return the second middle node.

Function Signature Example

1
ListNode* middleNode(ListNode* head);

Example

1
2
Input:  head = [1, 2, 3, 4, 5]
Output: [3, 4, 5]

Constraints

  • The number of nodes is in the range [1, 100].

Solution Approach

  • Use two pointers:
    • slow moves one step at a time.
    • fast moves two steps at a time.
  • When fast reaches the end, slow will be at the middle.

Complexity

  • Time: O(n)
  • Space: O(1)

Edge Cases

  • Length 1 or 2.

3. Valid Parentheses (LC 20)

Problem Description
Given a string containing just the characters '(', ')', '{', '}', '[', and ']', determine if the input string is valid.

A string is valid if:

  1. Open brackets are closed by the same type of brackets.
  2. Open brackets are closed in the correct order.

Function Signature Example

1
bool isValid(string s);

Example

1
2
Input:  s = "()[]{}"
Output: true

Constraints

  • 1 <= s.length <= 10^4
  • s consists of parentheses only.

Solution Approach

  • Use a stack:
    • Push opening brackets.
    • When encountering a closing bracket, check the stack top.
  • Return true if stack is empty at the end.

Complexity

  • Time: O(n)
  • Space: O(n)

Edge Cases

  • Single closing bracket at start.
  • Nested brackets.

4. Maximum Depth of Binary Tree (LC 104)

Problem Description
Given the root of a binary tree, return its maximum depth.

Function Signature Example

1
int maxDepth(TreeNode* root);

Example

1
2
Input:  root = [3, 9, 20, null, null, 15, 7]
Output: 3

Constraints

  • The number of nodes is in the range [0, 10^4].

Solution Approach

  • DFS: Recursively compute max(leftDepth, rightDepth) + 1.
  • BFS: Level order traversal and count the levels.

Complexity

  • Time: O(n)
  • Space: O(h) for recursion stack or O(n) BFS queue.

Edge Cases

  • Empty tree.

5. Merge K Sorted Lists (LC 23)

Problem Description
You are given an array of k linked lists, each sorted in ascending order. Merge all the linked lists into one sorted linked list and return it.

Function Signature Example

1
ListNode* mergeKLists(vector<ListNode*>& lists);

Example

1
2
Input:  lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]

Constraints

  • k == lists.length
  • 0 <= k <= 10^4
  • 0 <= lists[i].length <= 500

Solution Approach

  1. Use a min-heap (priority queue) to always take the smallest current node among the k lists.
  2. Or apply divide and conquer merging pairs.

Complexity

  • Time: O(N log k), N = total nodes.
  • Space: O(k) heap or O(1) extra space for divide & conquer.

Edge Cases

  • Empty list of lists.
  • All lists empty.

94. Binary Tree Inorder Traversal (LC 94)

Problem Description
Return the inorder traversal of a binary tree’s nodes’ values (Left → Root → Right).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
vector<int> inorderTraversal(TreeNode* root);

Example

1
2
3
4
5
6
yaml


复制编辑
Input: root = [1,null,2,3]
Output: [1,3,2]

Constraints

  • Number of nodes ∈ [0, 10^4]
  • Node values can be any int
  • Tree may be skewed

Solution Approach

  1. Recursive DFS: traverse left, visit root, traverse right.
  2. Iterative with stack: simulate recursion (push all lefts, then pop/visit, go right).
  3. Morris traversal (optional): threaded binary tree to achieve O(1) extra space.

Complexity

  • Time: O(n)
  • Space: O(h) recursion/stack; Morris is O(1) extra space

Edge Cases

  • Empty tree → return []
  • Single node
  • Degenerate chain (all left/all right)

Interview 30s Pitch

“Inorder is left-root-right. I’ll do iterative with a stack to avoid recursion limits: push left chain, pop/visit, then go right. It’s O(n) time and O(h) space. I can also mention Morris for O(1) extra space.”


144. Binary Tree Preorder Traversal (LC 144)

Problem Description
Return the preorder traversal of a binary tree (Root → Left → Right).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
vector<int> preorderTraversal(TreeNode* root);

Example

1
2
3
4
5
6
yaml


复制编辑
Input: root = [1,null,2,3]
Output: [1,2,3]

Constraints

  • Nodes up to 10^4
  • May be unbalanced

Solution Approach

  1. Recursive: visit root, then left, then right.
  2. Iterative stack: push root; each step pop node, record value, push right then left.

Complexity

  • Time: O(n)
  • Space: O(h)

Edge Cases

  • Empty tree
  • Single node
  • Skewed tree

Interview 30s Pitch

“Preorder is root-left-right. I’ll use a stack: pop node, record value, push right then left so left is processed first. O(n) time, O(h) space.”


104. Maximum Depth of Binary Tree (LC 104)

Problem Description
Return the maximum depth (number of nodes along the longest path from root to a leaf).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
int maxDepth(TreeNode* root);

Example

1
2
3
4
5
6
yaml


复制编辑
Input: root = [3,9,20,null,null,15,7]
Output: 3

Constraints

  • Nodes up to 10^4

Solution Approach

  1. DFS recursion: 1 + max(depth(left), depth(right)), null → 0.
  2. BFS level order: count the number of levels.

Complexity

  • Time: O(n)
  • Space: O(h) for DFS; up to O(n) for BFS queue

Edge Cases

  • Empty tree → 0
  • Single node
  • Degenerate chain

Interview 30s Pitch

“I’ll use DFS: null returns 0; otherwise 1 + max(left, right). O(n) time, O(h) space. BFS by levels also works.”


108. Convert Sorted Array to Binary Search Tree (LC 108)

Problem Description
Given an increasing array, convert it to a height-balanced BST.

Function Signature Example

1
2
3
4
5
cpp


复制编辑
TreeNode* sortedArrayToBST(vector<int>& nums);

Example

1
2
3
4
5
6
makefile


复制编辑
Input: nums = [-10,-3,0,5,9]
Output: height-balanced BST rooted at 0

Constraints

  • 1 <= nums.size() <= 10^4
  • Strictly increasing or non-decreasing

Solution Approach

  1. Divide & Conquer: pick mid as root; recursively build left from [l..mid-1], right from [mid+1..r].
  2. Ensures height balance by construction.

Complexity

  • Time: O(n)
  • Space: O(log n) recursion stack (average)

Edge Cases

  • Single element → single-node tree
  • Even length (choose left-mid or right-mid consistently)
  • Large arrays (tail recursion depth)

Interview 30s Pitch

“Use divide-and-conquer: choose the middle element as root to keep balance, then recurse on left/right halves. It’s O(n) with O(log n) stack.”


226. Invert Binary Tree (LC 226)

Problem Description
Invert a binary tree: swap left and right children of every node.

Function Signature Example

1
2
3
4
5
cpp


复制编辑
TreeNode* invertTree(TreeNode* root);

Example

1
2
3
4
5
6
makefile


复制编辑
Input: [4,2,7,1,3,6,9]
Output: [4,7,2,9,6,3,1]

Constraints

  • Nodes up to 10^4

Solution Approach

  1. DFS recursion: swap left and right then recurse.
  2. BFS/DFS iterative: queue/stack, visit each node, swap children.

Complexity

  • Time: O(n)
  • Space: O(h) (DFS) or O(w) (BFS queue, w = max width)

Edge Cases

  • Empty tree → null
  • Single node
  • Highly unbalanced tree

Interview 30s Pitch

“For each node, swap left and right and recurse/iterate. It’s a full traversal: O(n) time, O(h) space.”


590. N-ary Tree Postorder Traversal (LC 590)

Problem Description
Return the postorder traversal of an N-ary tree (all children → node).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
vector<int> postorder(Node* root);

Example

1
2
3
4
5
6
lua


复制编辑
Input: root with children [[1],[3,2,4],[5,6]]
Output: [5,6,3,2,4,1]

Constraints

  • Total nodes up to 10^4
  • Each node has children list

Solution Approach

  1. Recursive: for each child, recurse; then record current node.
  2. Iterative: stack + output list; root→stack, pop and append value, push children; finally reverse result.

Complexity

  • Time: O(n)
  • Space: O(h) recursion/stack

Edge Cases

  • Empty tree → []
  • Node with many children
  • Deep but narrow structure

Interview 30s Pitch

“Postorder means process all children before the node. Recursively it’s natural; iteratively I do a modified preorder and reverse the result. O(n) time.”


98. Validate Binary Search Tree (LC 98)

Problem Description
Determine if a binary tree is a valid BST (strictly increasing in-order; or every node satisfies min < val < max).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
bool isValidBST(TreeNode* root);

Example

1
2
3
4
5
6
vbnet


复制编辑
Input: [2,1,3]
Output: true

Constraints

  • Nodes up to 10^4
  • Values may be INT_MIN/INT_MAX

Solution Approach

  1. Inorder check: inorder traversal must be strictly increasing; track previous value with 64-bit sentinel.
  2. Bounds recursion: pass down (low, high) bounds; check low < val < high.

Complexity

  • Time: O(n)
  • Space: O(h)

Edge Cases

  • Equal values on BST path (should be invalid)
  • INT limits (use long long bounds)
  • Empty tree → true

Interview 30s Pitch

“I’ll use inorder traversal ensuring strictly increasing values, guarding INT limits with 64-bit. Alternatively, pass low/high bounds. O(n) time, O(h) space.”


103. Binary Tree Zigzag Level Order Traversal (LC 103)

Problem Description
Return level order traversal but alternate direction on each level (left→right, then right→left, …).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
vector<vector<int>> zigzagLevelOrder(TreeNode* root);

Example

1
2
3
4
5
6
lua


复制编辑
Input: [3,9,20,null,null,15,7]
Output: [[3],[20,9],[15,7]]

Constraints

  • Nodes up to 10^4

Solution Approach

  1. BFS: normal level-order with a queue.
  2. For each level, if it’s an odd level, reverse the collected list (or build from back).
    • Alternatively use deque and alternate push order.

Complexity

  • Time: O(n)
  • Space: O(n)

Edge Cases

  • Empty tree → []
  • Single level
  • Highly unbalanced tree

Interview 30s Pitch

“I’ll do BFS by levels and alternate output order per level—either reverse on odd levels or build with a deque. O(n) time, O(n) space.”


105. Construct Binary Tree from Preorder and Inorder Traversal (LC 105)

Problem Description
Build a binary tree from its preorder and inorder traversal arrays (values are unique).

Function Signature Example

1
2
3
4
5
cpp


复制编辑
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder);

Example

1
2
3
4
5
6
makefile


复制编辑
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
Output: root of the constructed tree

Constraints

  • 1 <= n <= 10^4
  • All node values unique

Solution Approach

  1. Hash map the inorder value → index for O(1) splits.
  2. Preorder’s first element is root; split inorder into left/right subtrees; recur with corresponding subarray ranges.
  3. Maintain preorder index as a global/reference pointer.

Complexity

  • Time: O(n)
  • Space: O(n) for the hash map + O(h) recursion

Edge Cases

  • Single node
  • Skewed tree (unbalanced arrays)
  • Invalid inputs (not in LeetCode scope)

Interview 30s Pitch

“Use preorder’s first as root, find it in inorder via a hash map, split into left/right, and recurse with index ranges. That’s O(n) with O(n) extra for the map.”

OOD Question

1. Design a Parking Lot System

  • Design a parking lot that can accommodate different types of vehicles such as cars, motorcycles, and trucks.
  • The system should support parking a vehicle, removing a vehicle, and tracking available spots.
  • Consider how to extend the design for multiple floors and different billing strategies (per hour, per day, membership discounts).

2. Design an Elevator System

  • Design an elevator control system for a building.
  • The system should handle requests from users to go up or down, move elevators accordingly, and optimize scheduling.
  • Consider multiple elevators, emergency handling, and access restrictions for certain floors.

3. Design a Vending Machine

  • Design a vending machine that sells snacks and drinks.
  • The system should support product selection, payment (cash, card), dispensing items, and returning change.
  • Consider extensibility for new payment methods, discount logic, and combo offers.

4. Design an Amazon Locker System

  • Design a locker system for package delivery and pickup.
  • Users should be able to receive a code or QR code to open the locker and retrieve their package.
  • Consider lockers of different sizes, handling expired/uncollected packages, and supporting both delivery agents and customers.

5. Design a Linux File Search Utility

  • Design a utility to search files in a file system.
  • The system should support searching by filename, size, type, content, or date.
  • Consider different search strategies (regex, fuzzy search), distributed search across servers, and filtering by file permissions.

6. Design an Online Book Reader

  • Design a system for reading e-books online.
  • The system should allow browsing books, reading, bookmarking, and searching within books.
  • Consider supporting audiobooks, synchronizing reading progress across devices, and recommending books to users.

7. Design a Ride Sharing System (Uber/Lyft simplified)

  • Design a ride-sharing service that matches riders with drivers.
  • The system should support creating a ride request, matching drivers, tracking trips, and processing payments.
  • Consider features like carpooling, different vehicle types (economy, premium, SUV), and real-time location tracking.